package com.top.art.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.top.art.bo.UserBO;
import com.top.art.bo.UserPageQueryBO;
import com.top.art.bo.UserUpdateBO;
import com.top.art.manager.UserInfoManager;
import com.top.art.tool.AuthTool;
import com.top.art.vo.AccountInfoVO;
import com.top.art.vo.ResVO;
import com.top.art.vo.UserInfoVO;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * <p>
 * 用户表 前端控制器
 * </p>
 *
 * @author hjh
 * @since 2020 -10-04
 */
@RestController
@RequestMapping("/userinfo")
public class UserInfoController {
    /**
     * manager
     */
    @Resource
    private UserInfoManager userInfoManager;

    /**
     * Create res vo.
     *
     * @param bo the bo
     * @return the res vo
     */
    @PostMapping(value = "/create")
    public ResVO<Boolean> create(@Validated @RequestBody UserBO bo) {
        AccountInfoVO account = AuthTool.currentUser();
        return new ResVO<>(userInfoManager.create(bo, account));
    }


    /**
     * Page res vo.
     *
     * @param bo the bo
     * @return the res vo
     */
    @PostMapping(value = "/page")
    public ResVO<Page<UserInfoVO>> page(@Validated @RequestBody UserPageQueryBO bo) {
        Page<UserInfoVO> page = userInfoManager.page(bo);
        return new ResVO<>(page);
    }

    /**
     * Update res vo.
     *
     * @param bo the bo
     * @return the res vo
     */
    @PostMapping(value = "/update")
    public ResVO<Boolean> update(@Validated @RequestBody UserUpdateBO bo) {
        boolean result = userInfoManager.update(bo);
        return new ResVO<>(result);
    }

}
